/**
 * @description: uuid
 * @param template uuid模板 默认
 * @return string
 */
export const generateUUID = (template: string = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx"): string => {
  // Helper function to generate a random hex digit
  const randomHexDigit = (c: string): string => {
    const r = crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c === "x" ? 0 : 4));
    return (c === "x" ? r : (r & 0x3) | 0x8).toString(16);
  };

  // Generate UUID based on template
  return template.replace(/[xy]/g, randomHexDigit);
};
